package com.hebeu.gfh.utils;


import com.hebeu.gfh.exception.AppExceptionCodeMsg;

public class Result<T> {

    private int code = 200; //返回状态码
    private String msg =  "success" ; //返回的message
    private T data; //返回的数据

    //构造函数
    private Result(int code,String msg,T data){
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public static <T> Result <T> success(){
        Result result = new Result(200, "success", null);
        return result;
    }

    //成功时传入data数据
    public static <T> Result <T> success(T data){
        Result result = new Result(200, "success", data);
        return result;
    }

    //成功时传入data和msg
    public static <T> Result success (String msg ,T data){
        Result result = new Result(200, msg, data);
        return result;
    }

    public static <T> Result error(AppExceptionCodeMsg exceptionCodeMsg){
        Result result = new Result(exceptionCodeMsg.getCode(),exceptionCodeMsg.getMsg(),null);
        return result;
    }

    //失败时传入code和msg
    public static <T> Result error(int code ,String msg){
        Result result = new Result(code, msg, null);
        return result;
    }

    public int getCode() {
        return code;
    }

    public String getMsg() {
        return msg;
    }

    public T getData() {
        return data;
    }
}


